﻿<UserControl x:Class="Samba.Modules.SettingsModule.RuleView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300"
     d:DesignWidth="300" xmlns:lex="http://schemas.root-project.org/xaml/presentation">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto">
            <StackPanel>
                <Label HorizontalAlignment="Left" Content="{LocText RuleName,Suffix=':'}" />
                <TextBox HorizontalAlignment="Left" MinWidth="200" Text="{Binding Name}" />
                <Label HorizontalAlignment="Left" Content="{LocText EventName,Suffix=':'}" />
                <ComboBox HorizontalAlignment="Left" MinWidth="150" ItemsSource="{Binding Events}"
                     DisplayMemberPath="EventName" SelectedValuePath="EventKey" SelectedValue="{Binding EventName}" />
                <GroupBox HorizontalAlignment="Left" Margin="0,3" Padding="1">
                    <GroupBox.Header>
                        <LocText ResourceIdentifierKey="ExecuteActionsIf" Suffix=":" />
                    </GroupBox.Header>
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{LocText SettingCheck,Suffix=':'}" MinWidth="130" />
                            <TextBox MinWidth="80" Margin="2" Text="{Binding SettingConstraintName}" />
                            <ComboBox Margin="3,0" MinWidth="45" IsEditable="True" Text="{Binding SettingConstraintOperation}" 
                                                  ItemsSource="{Binding Operations}"/>
                            <TextBox MinWidth="80" Margin="2" Text="{Binding SettingConstraintValue}" />
                        </StackPanel>
                        <ItemsControl ItemsSource="{Binding Constraints}" HorizontalAlignment="Left">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Margin="0,3">
                                        <Label Content="{Binding NameDisplay}" MinWidth="130" />
                                        <ComboBox Margin="3,0" MinWidth="45" IsEditable="True" Text="{Binding Operation}" 
                                                  ItemsSource="{Binding Operations}"/>
                                        <ComboBox MinWidth="80" IsEditable="True" 
                                                  ItemsSource="{Binding Values}" Text="{Binding Value}"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </GroupBox>
                <StackPanel Orientation="Horizontal">
                    <Label HorizontalAlignment="Left" Content="{LocText Actions,Suffix=':'}" />
                    <TextBlock Margin="2,5,0,0">
                        <Hyperlink Command="{Binding SelectActionsCommand}">
                            <TextBlock Text="{Binding Path=SelectActionsCommand.Caption}" />
                        </Hyperlink>
                    </TextBlock>
                </StackPanel>
                <Grid HorizontalAlignment="Left">
                    <ItemsControl ItemsSource="{Binding Actions}" HorizontalAlignment="Left">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Expander Style="{StaticResource MainViewExpander}" Header="{Binding Name}" IsExpanded="False"
                                     Margin="2">
                                    <ItemsControl ItemsSource="{Binding ParameterValues}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal" Margin="0,3">
                                                    <Label Content="{Binding Name}" MinWidth="120" />
                                                    <ComboBox Text="{Binding Value}" MinWidth="80" IsEditable="True" ItemsSource="{Binding ParameterValues}" />
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </Expander>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Grid>
            </StackPanel>
        </ScrollViewer>
        <StackPanel Grid.Row="1">
            <Button HorizontalAlignment="Left" Margin="0,10,3,0" MinWidth="70" Content="{Binding SaveCommand.Caption}"
                 Command="{Binding SaveCommand}" />
            <Label Content="{Binding Error}" Foreground="Red" />
        </StackPanel>
    </Grid>
</UserControl>